package controller;

import javax.swing.table.AbstractTableModel;

import modeles.Contact;
import utilitaire.ListContact;

/**
 * 
 * Class Controller du tableau de contact
 * contacts		Objet ListContact
 * entetes		Objet String[]
 * 
 * @author Paul BEZARD-FALGAS
 *
 */
public class ControllerTab extends AbstractTableModel {
	    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ListContact contacts;
    private final String[] entetes = {"Name", "FirstName", "Company Address", "Personnal Phone", "Professional Phone", "Home Page", "Email"};
 
    
    public ControllerTab(ListContact list) {
        super();
        this.contacts = list;
    }
 
    public Contact get(int rowIndex){
    	return contacts.get(rowIndex);
    }
    
    public int getRowCount() {
        return contacts.size();
    }
 
    public int getColumnCount() {
        return entetes.length;
    }
 
    public String getColumnName(int columnIndex) {
        return entetes[columnIndex];
    }
 
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0:
                return contacts.get(rowIndex).getName();
            case 1:
                return contacts.get(rowIndex).getFirstName();
            case 2:
                return contacts.get(rowIndex).getCompanyAddress();
            case 3:
                return contacts.get(rowIndex).getPersonalPhone();
            case 4:
                return contacts.get(rowIndex).getProfessionalPhone();
            case 5:
                return contacts.get(rowIndex).getHomePage();
            case 6:
                return contacts.get(rowIndex).getEmail();
            default:
                return null; //Ne devrait jamais arriver
        }
    }
 
    public void removeContact(int rowIndex) {
    	contacts.remove(rowIndex);
 
        fireTableRowsDeleted(rowIndex, rowIndex);
    }
    
    public ListContact getList(){
    	return contacts;
    }

	public void removeAllElements() {
		contacts = null;
	}

}
